 $(function(){

  // 记录当前页
  var current = 1;
  var total = '';
  // 1-省钱控商品列表
  function render() {
    $.ajax({
      url: 'http://127.0.0.1:9090/api/getmoneyctrl',
      data: {
        pageid: current,
      },
      dataType: 'json',
      success: function(info){
        // console.log(info);
        $('.content').html(template('tmp',info))
        total = Math.ceil(info.totalCount/10);
       for(var i = 1; i <= total; i++) {
        var txt = $('#page-select>[value='+ i +']').text()+total;
        $('#page-select>[value='+ i +']').text(txt)
       }
      }
    })
  } 
  render();

  // 下一页
  $('.content').on('click','.page-under',function(){
    if(current < total) {
      // console.log(current);
      current++
     $('#page-select').val(current).prop('selected')
      
  
      render();
    }
  })

  // 上一页
  $('.content').on('click','.page-on',function(){
    if(current > 1) {
      current--
      // console.log(current);
      // $('#page-select').val(current)
      
      // $('#page-select').prop();
      render();
    }
  })
  
  // 下拉菜单
  $('.content').on('change','#page-select',function(){
    var val = $(this).val()  
    current = val;
    // $('#page-select').val(current)
      
    //   $('#page-select').prop();
    render();
    
  })
})